/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.develop.server;

import java.util.Date;
import java.util.Queue;
  
/**
 *
 * @author Phillip
 */
@Deprecated
public class Game extends Thread
{

    private GameServer gameServer;
    private Player playerOne;
    private Player playerTwo;
   
    private int id;
    private Date startTime;
    private Date endTime;
    private String packet;

    public Game( GameServer gameServer, Player playerOne, Player playerTwo, int id )
    {
        this.gameServer = gameServer;
        this.playerOne = playerOne;
        this.playerTwo = playerTwo;
        this.id = id;

    }

    public Player getPlayerOne()
    {
        return playerOne;
    }

    public Player getPlayerTwo()
    {
        return playerTwo;
    }  
    protected void chooseSides()
    {
        // @todo Übergabe-Art
        // @todo Zufall oder Regel zum wählen der Seiten implementieren
        this.playerOne.write( "SETPLAYER0\n" );
        
        this.playerTwo.write( "SETPLAYER1\n" );
    }

    @Override
    public void run()
    {

        chooseSides();
        while ( true )
        {

            if ( !playerOne.getPackets().isEmpty() )
            {

                while ( ( packet = playerOne.getPackets().poll() ) != null )
                {
                    gameServer.debug( "packet was: " + packet );
                    playerTwo.write( packet+"SETPOS" );

                }
            }
            if ( !playerTwo.getPackets().isEmpty() )
            {

                while ( ( packet = playerTwo.getPackets().poll() ) != null )
                {
                    /*
                    byte[] msg = packet.getBytes();
                    for(int i = 0; i < msg.length; i++)
                    {
                        gameServer.debug("Byte["+i+"]="+ msg[i]);
                    }
                     * 
                     */
                    playerOne.write( packet+"SETPOS" );
                }
            }
        }

    }
}
